﻿@model List<HmPMer.Entity.PayType>

@{
    ViewBag.Title = "商户支付类型";
    Layout = "~/Views/Shared/_Content.cshtml";
    var channelList = new HmPMer.Business.PayBll().GetPayTypeList();
    var IBList = new HmPMer.Business.InterfaceBll().GetInterfaceBusinessList(1);
    var SchemeList = new HmPMer.Business.WithdrawBll().GetListAccountScheme();
}

<style>
    .layui-unselect {
        margin-top: 5px;
    }
</style>

<form class="layui-form" id="formdata">
    @Html.Hidden("InterfaceCode", Request["Code"])
    <table class="layui-table mag0">
        <colgroup>
            <col width="5%">
            <col width="45%">
            <col width="45%">

        </colgroup>
        <thead>
            <tr>
                <td align="center"><input type="checkbox" lay-filter="cbkal1" name="" lay-skin="primary">类型</td>
                <td align="center">默认接口商</td>
                <td align="center">入账方案</td>
            </tr>
        </thead>
        <tbody id="menuallbody">
            @foreach (var item in channelList)
            {
                var pm = Model.Where(a => a.PayCode.Equals(item.PayCode)).FirstOrDefault();
                <tr>
                    <td>
                        <input type="checkbox" lay-filter="cbk" class="cbkbox" name="cbktype" title="@item.PayName" value="@(item.PayCode)" @(pm != null ? "checked" : "") lay-skin="primary">
                    </td>
                    <td>
                        <select id="InterfaceCode@(item.PayCode)" name="" lay-verify="" style="width:100px" lay-filter="">
                            <option value="">默认</option>
                            @foreach (var item2 in IBList)
                            {
                                <option value="@item2.Code" @(pm != null && pm.DefaulInfaceCode == item2.Code ? "selected" : "")>@item2.Name</option>
                            }
                        </select>
                    </td>
                    <td>
                        <select id="AccountScheme@(item.PayCode)" name="" lay-verify="" style="width:100px" lay-filter="">
                            <option value="">请选择</option>
                            @foreach (var item3 in SchemeList)
                            {
                                <option value="@item3.Id" @(pm != null && pm.AccountScheme == item3.Id ? "selected" : "")>@item3.name</option>
                            }
                        </select>
                    </td>
                </tr>
            }

        </tbody>
    </table>
    <div class="magt10" style="text-align:center">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="systemParameter" type="button" id="btn_submit">立即提交</button>
        </div>
    </div>
</form>

<script>
    layui.use(['hm', 'form'], function () {
        var form = layui.form,
            $ = layui.jquery,
            hm = layui.hm;

        form.on('checkbox(cbkal1)', function (data) {
            var id = data.elem.value;
            var child = $('#menuallbody').find('input[type="checkbox"]');
            child.each(function (index, item) {
                item.checked = data.elem.checked;
            });
            form.render('checkbox');

        });


        //提交表单
        $("#btn_submit").click(function () {

            var arr = new Array()
            $("input[name='cbktype']:checked").each(function (i, v) {
                var vcode = $("#InterfaceCode" + v.value).val();
                var vscheme = $("#AccountScheme" + v.value).val();
                arr[i] = v.value + "#" + vcode + "#" + vscheme;                
            })
            var index = layer.msg('修改中，请稍候', { icon: 16, time: false, shade: 0.8 });
            setTimeout(function () {
                layer.close(index);
                hm.ajax("/Pay/SetInterfaceType", {
                    data: { InterfaceCode: $("#InterfaceCode").val(), PayCode: arr.join(','),type:'@(Request["Type"])' },
                    type: "POST",
                    dataType: 'json',
                    success: function (result) {
                        if (result.Success) {
                            layer.msg("操作成功！", { icon: 1, time: 300 }, function () {
                                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                parent.tableIns.reload();
                                parent.layer.close(index);
                            });
                        } else {
                            layer.msg(result.Message);
                        }
                    },
                    error: function (x, t, e) {
                        layer.closeAll();
                    }
                });

            }, 500);

        });


    });
</script>
